package com.tsingteng.cosfun.ui.cosfun.presenter;

import com.tsingteng.cosfun.bean.AttentFansbean;
import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.RecommenResp;
import com.tsingteng.cosfun.ui.cosfun.contract.AttentContract;
import com.tsingteng.cosfun.ui.cosfun.imodel.AttentModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AttantPresenter implements AttentContract.IAttentPresenter {
    AttentModel attentModel = null;
    AttentContract.IAttentView iAttentView = null;

    public AttantPresenter(AttentContract.IAttentView iAttentView) {
        this.attentModel = new AttentModel();
        this.iAttentView = iAttentView;
    }


    @Override
    public void getAttentList(String userId, String pageNo) {
        attentModel.getAttentList(userId, pageNo, new Callback<BaseDataBean<AttentFansbean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<AttentFansbean>> call, Response<BaseDataBean<AttentFansbean>> response) {
                if (response.body()==null)return;
                if (response.body().getData()==null) return;
                iAttentView.success(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseDataBean<AttentFansbean>> call, Throwable t) {
                iAttentView.failure(0, t.getMessage());
            }
        });
    }

    @Override
    public void getCommentInfo() {
        attentModel.getFocusListInfo(new Callback<BaseDataBean<RecommenResp>>() {
            @Override
            public void onResponse(Call<BaseDataBean<RecommenResp>> call, Response<BaseDataBean<RecommenResp>> response) {
                if (null ==response.body()){
                    return;
                }
                if (null == response.body().getData())return;
                iAttentView.showAttentList(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseDataBean<RecommenResp>> call, Throwable t) {
                  iAttentView.failure(0,t.getMessage());
            }
        });
    }

    @Override
    public void loginFollowFans(String follow_id) {
        attentModel.getFollowNotification(follow_id, new Callback<BaseDataBean<FollowBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
                if (null ==response.body()){
                    return;
                }
                if (null == response.body().getData())return;
                iAttentView.getFollowResult(response.body().getData());
            }

            @Override
            public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iAttentView.failure(0,t.getMessage());
            }
        });
    }

    @Override
    public void loginNoFollow(String follow_id, int position) {
       attentModel.getNoFollowNotification(follow_id, new Callback<BaseDataBean<FollowBean>>() {
           @Override
           public void onResponse(Call<BaseDataBean<FollowBean>> call, Response<BaseDataBean<FollowBean>> response) {
               if (null ==response.body()){
                   return;
               }
               if (null == response.body().getData())return;
               iAttentView.showNoFollowResult(response.body().getData());
           }

           @Override
           public void onFailure(Call<BaseDataBean<FollowBean>> call, Throwable t) {
                iAttentView.failure(0,t.getMessage());
           }
       });
    }
}
